var e, t = (e = require("@vant/weapp/toast/toast")) && e.__esModule ? e : {
    default: e
};

var a = require("../../utils/request"), o = require("../../utils/api"), r = require("../../utils/storage"), s = require("../../utils/config"), i = require("../../utils/encrypt");

Component({
    properties: {},
    data: {
        themeColor: getApp().globalData.themeColor,
        showLoginButton: !0,
        showModal: !1,
        userBase: {
            avatar200: s.resourceRoot + "avatar.png"
        },
        nickName: "",
        avatarUrl: s.resourceRoot + "avatar.png"
    },
    lifetimes: {
        attached: function() {},
        detached: function() {},
        ready: function() {
            this.setHeader();
        }
    },
    methods: {
        avatarClick: function() {
            this.data.showLoginButton || wx.navigateTo({
                url: "/pages/my-link-information-maintenance/my-link-information-maintenance"
            });
        },
        login: function(e) {
            this.closeLogin(), wx.showLoading({
                title: "正在登录中..."
            });
            var s = this;
            "getPhoneNumber:ok" == e.detail.errMsg ? a.request(a.HttpMethod.POST, o.apiRoute.login, {
                code: e.detail.code,
                encryptedData: e.detail.encryptedData,
                iv: e.detail.iv
            }).then(function(e) {
                if (wx.hideLoading(), "20000" == e.code) {
                    s.triggerEvent("onShowLogOut");
                    var a = i.encryptMobile(e.data.phoneNumber);
                    s.setData({
                        showLoginButton: !1,
                        userBase: e.data.userBase,
                        nickName: a
                    }), (0, t.default)({
                        message: "登录成功",
                        duration: 5e3
                    }), r.setStorage(r.storageKey.customerCenterJwt, e.data.token), r.setStorage(r.storageKey.customerCenterJwtExpired, e.data.expired), 
                    r.setStorage(r.storageKey.uid, e.data.userBase.uid), r.setStorage(r.storageKey.userBase, e.data.userBase), 
                    r.setStorage(r.storageKey.phoneNumber, e.data.phoneNumber);
                } else wx.hideLoading(), (0, t.default)({
                    message: "登录失败，".concat(e.message),
                    duration: 5e3
                });
            }) : (wx.hideLoading(), (0, t.default)({
                message: "请选择允许获取手机号",
                duration: 5e3
            }));
        },
        removeUserBase: function() {
            this.setData({
                userBase: {
                    avatar200: s.resourceRoot + "avatar.png"
                },
                nickName: "",
                showLoginButton: !0
            });
        },
        setHeader: function() {
            if (r.isLogin()) {
                var e = r.getStorageSync(r.storageKey.userBase), t = r.getStorageSync(r.storageKey.phoneNumber), a = i.encryptMobile(t);
                this.setData({
                    userBase: e,
                    nickName: a,
                    showLoginButton: !1
                });
            } else this.setData({
                userBase: {
                    avatar200: s.resourceRoot + "avatar.png"
                },
                nickName: "",
                showLoginButton: !0
            });
        },
        getUserProfile: function() {
            r.isLogin() || wx.navigateTo({
                url: "/pages/authorize/authorize?path=my"
            });
        },
        closeLogin: function() {
            this.setData({
                showModal: !1
            });
        }
    }
});